package com.audaque.springboot.foshanupload.web.raspcloud.controller;

import com.audaque.springboot.foshanupload.web.raspcloud.entity.Menu;
import com.audaque.springboot.foshanupload.web.raspcloud.mapper.ext.MenuExtMapper;
import com.audaque.springboot.foshanupload.web.raspcloud.req.MenuReq;
import com.audaque.springboot.foshanupload.web.raspcloud.service.IMenuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 后台菜单表 前端控制器
 * </p>
 *
 * @author chinaben
 * @since 2025-07-02
 */
@RestController

@Api(value = "后台菜单表 前端控制器")

@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuExtMapper menuExtMapper;
    @Autowired
    private IMenuService iMenuService;


    @PostMapping(value = "/page")
    @ApiOperation(value = "后台菜单表 分页查询")
    public Page<Menu> page(@RequestBody MenuReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        Page<Menu> page = iMenuService.page(new Page<>(req.getPage(), req.getRows()),queryWrapper);
        return page;
    }




    @PostMapping(value = "/list")
    @ApiOperation(value = "后台菜单表 列表查询")
    public List<Menu> list(@RequestBody MenuReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        List<Menu> list = iMenuService.list(queryWrapper);
        return list;
    }





    @GetMapping(value = "/{id}")
     @ApiOperation(value = "后台菜单表 单体查询")
    public Menu getById(@PathVariable("id") String id) {
        Menu one=iMenuService.getById(id);
        return one;
    }

    @PostMapping(value = "/create")
     @ApiOperation(value = "后台菜单表 创建")
    public void create(@RequestBody Menu params) {
        iMenuService.save(params);
    }

    @PostMapping(value = "/delete/{id}")
     @ApiOperation(value = "后台菜单表 删除")
    public void delete(@PathVariable("id") String id) {
        iMenuService.removeById(id);
    }


      @PostMapping(value = "/enable/{id}/{enableYn}")
         @ApiOperation(value = "用户 是否启用（0禁用 1启用）")
           public void enable(@PathVariable("id") String id,@PathVariable("enableYn") Boolean enableYn) {
               Menu entity = new Menu();
               entity.setEnableYn(enableYn);
               iMenuService.updateById(entity);
           }



            @PostMapping(value = "/delFlag/{id}/{delFlag}")
        @ApiOperation(value = "用户 删除标志（0正常 1停用）")
           public void delFlag(@PathVariable("id") String id,@PathVariable("delFlag") Boolean delFlag) {
               Menu entity = new Menu();
               entity.setDelFlag(delFlag);
               iMenuService.updateById(entity);
           }


    @PostMapping(value = "/update")
     @ApiOperation(value = "后台菜单表 更新")
    public void update(@RequestBody Menu params) {
        iMenuService.updateById(params);
    }















}
